# coding=utf-8

import cv2
import numpy
import utils


def strokeEdges(src, dst, blur_k_size=7, edge_k_size=5):
    """
    :param src:
    :param dst:
    :param blur_k_size:
    :param edge_k_size:
    """
    if blur_k_size >= 3:
        blurredSrc = cv2.medianBlur(src, blur_k_size)
        gray_src = cv2.cvtColor(blurredSrc, cv2.COLOR_BGR2GRAY)
    else:
        gray_src = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)

    cv2.Laplacian(gray_src, cv2.CV_8U, gray_src, gray_src, ksize=edge_k_size)
    normalized_inverse_alpha = (1.0 / 255) * (255 - gray_src)
    channels = cv2.split(src)
    for channel in channels:
        channel[:] = channel * normalized_inverse_alpha
    cv2.merge(channels, dst)


class v_convolution_filter(object):
    """
    v convolution filter.
    """
    def __init__(self, kernel):
        self._kernel = kernel

    def apply(self, src, dst):
        cv2.filter2D(src, -1, self._kernel, dst)


class sharpen_filter(v_convolution_filter):
    """
    sharpen filter.
    """
    def __init__(self):
        kernel = numpy.array([
            [-1, -1, -1],
            [-1, 9, -1],
            [-1, -1, -1],
        ]);
        v_convolution_filter.__init__(self, kernel)

